package io.renren.common.filter;

import io.renren.common.utils.CASUtil;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author cmy
 * @title: LocalUserInfoFilter
 * @projectName my-security
 * @description: TODO
 * @date 2019/12/319:48
 */
public class LocalUserInfoFilter implements Filter {

//    private String localcasLogin;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
//        localcasLogin = filterConfig.getInitParameter("localcasLogin");
    }


    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request_ = (HttpServletRequest) servletRequest;
        HttpServletResponse response_ = (HttpServletResponse) servletResponse;
        String loginName = CASUtil.getAccountNameFromCas(request_);
        String requestURI = request_.getRequestURI();
        if (loginName != null && !loginName.isEmpty()) {
            System.out.println("访问者 ：" + loginName);
//                response_.sendRedirect(request_.getContextPath() + "/sys/casLogin");
//            } else {
        }else {
            System.err.println("未获取访问者用户名 ...");
        }
        filterChain.doFilter(servletRequest, servletResponse);
    }
}
